<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>栈</title>
</head>

<body>

</body>
<script>
    class Stack {
        constructor() {
            this.arr = []
        }
        add(ele) {
            this.arr.push(ele)
        }
        del() {
            return this.arr.pop()
        }
        clear() {
            return this.arr.length = 0
        }
        isemply() {
            return this.arr.length === 0
        }
    }

    let stack = new Stack()
    stack.add(1)
    stack.add(2)
    stack.add(3)
    stack.add(4)
    stack.add(5)
    console.log(stack);
    stack.del()
    console.log(stack.isemply());
    stack.clear()
    console.log(stack);


    const binary = (number) => {
        let stack = new Stack()
        let top = ''
        let remain = 0 // 余数
        if (number > 0) {
            remain = number % 2
            stack.add(remain)
            number = Math.floor(number / 2)
        }
        while (!stack.isemply()) {
            top += stack.del()
        }
        return top
    }

    console.log(binary(113));
</script>

</html>

